using UnityEngine;

public class PlayerAnimationTriggers : MonoBehaviour
{
    private Player Player => GetComponentInParent<Player>();

    private void AnimationTrigger()
    {
        Player.AnimationTrigger();
    }

    private void AttackTrigger()
    {
        AudioManager.Instance.PlaySfx(2, null);
        Collider2D[] results = new Collider2D[10];
        var size = Physics2D.OverlapCircleNonAlloc(Player.AttackPoint.position, Player.attackCheckRadius, results,
            LayerMask.GetMask("Enemy"));
        for (int i = 0; i < size; i++)
        {
            if (!results[i].TryGetComponent(out EnemyStats enemyStats))
                return;
            Player.Stats.DoDamage(enemyStats);
            // inventory get weapon call item effect
            WeaponEffect(enemyStats.transform);
        }
    }

    private void WeaponEffect(Transform transform)
    {
        ItemDataEquipment weaponData = Player.Inventory.GetEquipment(EquipmentType.Weapon);
        weaponData?.Effect(transform, Player);
    }

    private void ThrowSword()
    {
        Player.SkillManager.Sword.CreateSword();
    }
}